package cn.zbh.basic.service.impl;

import cn.zbh.basic.mapper.BasicMapper;
import cn.zbh.basic.query.BasicQuery;
import cn.zbh.basic.service.IBasicService;
import cn.zbh.basic.util.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class BasicServiceImpl<T> implements IBasicService<T> {
    @Autowired
    private BasicMapper<T> mapper;


    @Override
    public T findById(long id) {
        return  mapper.findById(id);
    }

    @Override
    public List<T> findAll() {
        return mapper.findAll();
    }

    @Override
    @Transactional
    public void add(T t) {
        mapper.add(t);
    }

    @Override
    @Transactional
    public void update(T T) {
        mapper.update(T);
    }

    @Override
    @Transactional
    public void delete(long id) {
        mapper.delete(id);
    }

    //分页信息
    @Override
    public PageList<T> query(BasicQuery Query){
        Integer counts = mapper.queryCount(Query);
        List<T> list = mapper.queryData(Query);
        return new PageList<T>(counts,list);
    }

    @Override
    public void patchDel(List<Long> ids) {
        mapper.patchDel(ids);
    }
}
